package com.ymatou.iapi.exp.testcase;

import java.math.BigDecimal;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonObject;
import com.ymatou.iapi.exp.parameter.CalcOrderReceivedCoinBean;
import com.ymatou.iapi.exp.service.CalcOrderReceivedCoinCall;
import com.ymatou.iapi.optrade.resp.TradingServiceResp;
import com.ymatou.iapi.userregister.parameter.UserRegisterInfoRequestDtoBean;
import com.ymatou.iapi.userregister.service.UserRegisterInfoRequestDtoCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.AccountCallServiceV2;
import com.ymttest.business.service.ExpCallService;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.business.service.YMTTrading.TradingCallService;
import com.ymttest.business.service.YMTTrading.TradingPlaceOrderCallService;
import com.ymttest.utils.YMTDateUtil;
/**
*计算订单可获得的金币数
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_CalcOrderReceivedCoin{
	private static CalcOrderReceivedCoinBean calcorderreceivedcoinBean;
	private static CalcOrderReceivedCoinCall calcorderreceivedcoinCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("计算订单可获得的金币数");
	}

	@Before
	public void caseUp() {
		calcorderreceivedcoinBean=new CalcOrderReceivedCoinBean();
		calcorderreceivedcoinCall=new CalcOrderReceivedCoinCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(calcorderreceivedcoinCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CalcOrderReceivedCoin_001() {
		Logger.start(true,"计算订单可获得的金币数成功");
		try {
			calcorderreceivedcoinBean.setOrderPrice("20.0");
			calcorderreceivedcoinCall.setData(calcorderreceivedcoinBean);
			calcorderreceivedcoinCall.callService();			
			JsonObject result = calcorderreceivedcoinCall.getJsonObject().get("Data").getAsJsonObject();
			Logger.verifyEquals("true", result.get("success").toString(), "验证success");
			Logger.verifyEquals("0", calcorderreceivedcoinCall.getString("BCode"), "验证BCode");
			int coin=calcorderreceivedcoinCall.getJsonObject().get("Data").getAsJsonObject().get("coin").getAsInt();
			int rate=calcorderreceivedcoinCall.getJsonObject().get("Data").getAsJsonObject().get("rate").getAsInt();
			Logger.verifyEquals(2,coin, "验证coin");
			Logger.verifyEquals(1,rate, "验证rate");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_CalcOrderReceivedCoin_002() {
		Logger.start(true,"不输入orderPrice参数返回0");
		try {
//			calcorderreceivedcoinBean.setOrderPrice("20.0");
			calcorderreceivedcoinCall.setData(calcorderreceivedcoinBean);
			calcorderreceivedcoinCall.callService();			
			JsonObject result = calcorderreceivedcoinCall.getJsonObject().get("Data").getAsJsonObject();
			Logger.verifyEquals("true", result.get("success").toString(), "验证success");
			Logger.verifyEquals("0", calcorderreceivedcoinCall.getString("BCode"), "验证BCode");
			int coin=calcorderreceivedcoinCall.getJsonObject().get("Data").getAsJsonObject().get("coin").getAsInt();
			Logger.verifyEquals(0,coin, "验证coin");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CalcOrderReceivedCoin_003() {
		Logger.start(true,"金额小于20不能获取金币数");
		try {
			calcorderreceivedcoinBean.setOrderPrice("19.99");
			calcorderreceivedcoinCall.setData(calcorderreceivedcoinBean);
			calcorderreceivedcoinCall.callService();			
			JsonObject result = calcorderreceivedcoinCall.getJsonObject().get("Data").getAsJsonObject();
			Logger.verifyEquals("true", result.get("success").toString(), "验证success");
			Logger.verifyEquals("0", calcorderreceivedcoinCall.getString("BCode"), "验证BCode");
			int coin=calcorderreceivedcoinCall.getJsonObject().get("Data").getAsJsonObject().get("coin").getAsInt();
			Logger.verifyEquals(0,coin, "验证coin");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CalcOrderReceivedCoin_004() {
		Logger.start(true,"计算订单可获得的金币数成功,金额余数舍弃(2X元按20算)");
		try {
			calcorderreceivedcoinBean.setOrderPrice("29.99");
			calcorderreceivedcoinCall.setData(calcorderreceivedcoinBean);
			calcorderreceivedcoinCall.callService();			
			JsonObject result = calcorderreceivedcoinCall.getJsonObject().get("Data").getAsJsonObject();
			Logger.verifyEquals("true", result.get("success").toString(), "验证success");
			Logger.verifyEquals("0", calcorderreceivedcoinCall.getString("BCode"), "验证BCode");
			int coin=calcorderreceivedcoinCall.getJsonObject().get("Data").getAsJsonObject().get("coin").getAsInt();
			Logger.verifyEquals(2,coin, "验证coin");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CalcOrderReceivedCoin_005() {
		Logger.start(true,"计算订单可获得的金币数成功,非psp新客倍率1");
		try {
			int rate=1;
			UserRegisterInfoRequestDtoBean urb = JUserCallService.initUserRegisterInfoRequestDtoBean();
			// urb.setDeviceId(TestDataManager.getRandomUUID().toString());
			UserRegisterInfoRequestDtoCall uc = JUserCallService.UserRegisterInfoRequestDtoCall(urb);
			Integer userId = uc.getUserid();
			calcorderreceivedcoinBean.setOrderPrice("20.0");
			
			calcorderreceivedcoinBean.setIsPspSeller(false);
			calcorderreceivedcoinBean.setSellerId(3383);
			calcorderreceivedcoinBean.setUserId(userId);
			calcorderreceivedcoinBean.setOrderTime(YMTDateUtil.getSysTime());
			
			calcorderreceivedcoinCall.setData(calcorderreceivedcoinBean);
			calcorderreceivedcoinCall.callService();			
			JsonObject result = calcorderreceivedcoinCall.getJsonObject().get("Data").getAsJsonObject();
			Logger.verifyEquals("true", result.get("success").toString(), "验证success");
			Logger.verifyEquals("0", calcorderreceivedcoinCall.getString("BCode"), "验证BCode");
			int coin=calcorderreceivedcoinCall.getJsonObject().get("Data").getAsJsonObject().get("coin").getAsInt();
			Logger.verifyEquals(2*rate,coin, "验证coin");
			int rrate=calcorderreceivedcoinCall.getJsonObject().get("Data").getAsJsonObject().get("rate").getAsInt();
			Logger.verifyEquals(rate,rrate, "验证rate");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CalcOrderReceivedCoin_006() {
		Logger.start(true,"计算订单可获得的金币数成功,psp新客倍率2");
		try {
			int rate=ExpCallService.pspRate;
			Logger.comment("准备订单数据");
			TradingServiceResp placeOrderResp = TradingPlaceOrderCallService.placeOrderWithLuxury(false);
			Logger.comment("充值");
			String acc=AccountCallServiceV2.getAccountId(Long.valueOf(placeOrderResp.getUserId()).intValue());
			AccountCallServiceV2.resetAccount(acc, new BigDecimal("10000"), new BigDecimal("0"));
			Logger.comment("余额支付");
			Long userId = placeOrderResp.getUserId();
			String orderId=String.valueOf(placeOrderResp.getMainOrderId());
			TradingCallService.payOrder(placeOrderResp.getUserId(), placeOrderResp.getPayableAmount(),
					placeOrderResp.getMainOrderId(), "13");
			
			Integer sellerId=((Long)placeOrderResp.getOrderList().get(0).getSellerId()).intValue();
			
			calcorderreceivedcoinBean.setOrderPrice("20.0");
			
			calcorderreceivedcoinBean.setIsPspSeller(true);
			calcorderreceivedcoinBean.setSellerId(sellerId);
			calcorderreceivedcoinBean.setUserId(userId.intValue());
			calcorderreceivedcoinBean.setOrderTime(YMTDateUtil.getSysTime());
			calcorderreceivedcoinBean.setOrderId(Long.valueOf(orderId));
			calcorderreceivedcoinCall.setData(calcorderreceivedcoinBean);
			calcorderreceivedcoinCall.callService();			
			JsonObject result = calcorderreceivedcoinCall.getJsonObject().get("Data").getAsJsonObject();
			Logger.verifyEquals("true", result.get("success").toString(), "验证success");
			Logger.verifyEquals("0", calcorderreceivedcoinCall.getString("BCode"), "验证BCode");
			int coin=calcorderreceivedcoinCall.getJsonObject().get("Data").getAsJsonObject().get("coin").getAsInt();
			Logger.verifyEquals(2*rate,coin, "验证coin");
			int rrate=calcorderreceivedcoinCall.getJsonObject().get("Data").getAsJsonObject().get("rate").getAsInt();
			Logger.verifyEquals(rate,rrate, "验证rate");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CalcOrderReceivedCoin_007() {
		Logger.start(true,"计算订单可获得的金币数成功,老客倍率5");
		try {
			int rate=ExpCallService.oldRate;
			Integer userId = ExpCallService.OldUser;
			
			Logger.comment("准备订单数据");
			TradingServiceResp placeOrderResp = TradingPlaceOrderCallService.placeOrderWithUserId(userId);
			Logger.comment("充值");
			String acc=AccountCallServiceV2.getAccountId(Long.valueOf(placeOrderResp.getUserId()).intValue());
			AccountCallServiceV2.resetAccount(acc, new BigDecimal("10000"), new BigDecimal("0"));
			Logger.comment("余额支付");
			String orderId=String.valueOf(placeOrderResp.getMainOrderId());
			TradingCallService.payOrder(placeOrderResp.getUserId(), placeOrderResp.getPayableAmount(),
					placeOrderResp.getMainOrderId(), "13");
			
			ExpCallService.resetCoinAccount(userId);
			
			calcorderreceivedcoinBean.setOrderPrice("20.0");
			
			calcorderreceivedcoinBean.setIsPspSeller(true);
			calcorderreceivedcoinBean.setSellerId(ExpCallService.OldSeller);
			calcorderreceivedcoinBean.setUserId(userId);
			calcorderreceivedcoinBean.setOrderTime(YMTDateUtil.getSysTime());
			calcorderreceivedcoinBean.setOrderId(Long.valueOf(orderId));
			calcorderreceivedcoinCall.setData(calcorderreceivedcoinBean);
			calcorderreceivedcoinCall.callService();			
			JsonObject result = calcorderreceivedcoinCall.getJsonObject().get("Data").getAsJsonObject();
			Logger.verifyEquals("true", result.get("success").toString(), "验证success");
			Logger.verifyEquals("0", calcorderreceivedcoinCall.getString("BCode"), "验证BCode");
			int coin=calcorderreceivedcoinCall.getJsonObject().get("Data").getAsJsonObject().get("coin").getAsInt();
			Logger.verifyEquals(2*rate,coin, "验证coin");
			int rrate=calcorderreceivedcoinCall.getJsonObject().get("Data").getAsJsonObject().get("rate").getAsInt();
			Logger.verifyEquals(rate,rrate, "验证rate");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}